﻿namespace DateControls
{
    using System.Text.RegularExpressions;

    /// <summary>
    /// Calendar control time selection enabled.
    /// </summary>
    public class DateTimePicker : DatePicker
    {
        private const string TIME_MASK = "99:99";
        private const string TIME_MASK_REGEXP = "\\s([0-1][0-9]|[2][0-3]):([0-5][0-9])";
        
        /// <summary>
        /// Gets the date format of the calendar.
        /// For example %d %m, %Y(Day/Month/Year)
        /// </summary>
        /// <value>The date format.</value>
        public override string DateFormat
        {
            get
            {
                return string.Format("{0} {1}", base.DateFormat, "%H:%M"); 
            }
        }

        /// <summary>
        /// Gets the validation expression.
        /// </summary>
        /// <value>The validation expression.</value>
        protected override Regex ValidationExpression
        {
            get
            {
                return new Regex(base.ValidationExpression + TIME_MASK_REGEXP);
            }
        }

        /// <summary>
        /// Gets or sets the type of the mask.
        /// </summary>
        /// <value>The type of the mask.</value>
        protected override AjaxControlToolkit.MaskedEditType MaskType
        {
            get
            {
                return AjaxControlToolkit.MaskedEditType.DateTime;
            }
        }

        /// <summary>
        /// Gets or sets the mask.
        /// </summary>
        /// <value>The mask.</value>
        protected override string Mask
        {
            get
            {
                return string.Format("{0} {1}", base.Mask, TIME_MASK);
            }
        }
        
        /// <summary>
        /// Sets additional setup to the calendar
        /// </summary>
        /// <param name="calendarSetup">The calendar setup.</param>
        protected override void SetAdditionalCalendarSetup(System.Text.StringBuilder calendarSetup)
        {
            calendarSetup.Append("showsTime : true,");
        }
    }
}